Stiffener Figures

In [85]:
import pandas as pd
import numpy as np
import re
import plotly.express as px
import pickle
from IPython.core.display import display, HTML
import plotly.io as pio
pio.renderers.default = "notebook"

#load saved plot.ly figures
with open('../plotlyfigs/stiffener-figs.pickle','rb') as f:
    fig=pickle.load(f)

#generate plots and csv files
for f in fig:
    arrays = []
    data = []
    x = f['layout']['xaxis']['title']
    xtitle = x
    y = f['layout']['yaxis']['title']
    if y == 'beta':
        ytitle = r'$\beta$'
    else:
        ytitle = y
    title = f['layout']['title']
    for i in range(len(f['data'])):
        arrays.extend([f['data'][i]['name']]*2)
        data.append(f['data'][i]['x'])
        data.append(f['data'][i]['y'])
    arrays = [arrays,[x,y]*len(f['data'])]
    tuples = list(zip(*arrays))
    data_t = [list(j) for j in zip(*data)]
    index = pd.MultiIndex.from_tuples(tuples, names=['name', 'axis'])
    df = pd.DataFrame(data_t, columns=index)
    #export data to csv
    mytitle = 'p' + re.search('\(.* (\d{3})\)',f['layout']['title'])[1] + '.csv'
    df.to_csv(mytitle)
    #plot data
    myfig = px.line(df.stack(0).reset_index(), x=x, y=y, color="name", title=title, labels={x:xtitle, y:ytitle, 'name':'rivet pitch'})
    myfig.show()
    display(HTML("<a href=\""+mytitle+"\">Download .csv</a>"))
    
In [83]:
import plotly.io as pio
pio.renderers
Out[83]:
Renderers configuration
-----------------------
    Default renderer: 'plotly_mimetype+notebook'
    Available renderers:
        ['plotly_mimetype', 'jupyterlab', 'nteract', 'vscode',
         'notebook', 'notebook_connected', 'kaggle', 'azure', 'colab',
         'cocalc', 'databricks', 'json', 'png', 'jpeg', 'jpg', 'svg',
         'pdf', 'browser', 'firefox', 'chrome', 'chromium', 'iframe',
         'iframe_connected', 'sphinx_gallery']
In [ ]: